/**
 * 自定义hooks函数
 * 函数名必须以use*开头
 */
import { h0 } from './fp';
import { useCallback } from 'react';
export default function useNav(departDate, dispatch, prevDay, nextDay) {
  //出发日期少于今天  前一天不可点击
  const isPrevDisable = h0(departDate) - h0() <= 0;

  //当出发日期 超过20天外  后一天不可点击
  const isNextDisable = h0(departDate) - h0() >= 20 * 24 * 3600 * 1000;

  // console.log(isPrevDisable);
  // console.log(isNextDisable);
  const prev = useCallback(() => {
    if (isPrevDisable) {
      return;
    }
    dispatch(prevDay());
  }, [dispatch, isPrevDisable, prevDay]);
  const next = useCallback(() => {
    if (isNextDisable) {
      return;
    }
    dispatch(nextDay());
  }, [dispatch, isNextDisable, nextDay]);
  return {
    isPrevDisable,
    isNextDisable,
    prev,
    next,
  };
}
